package com.ydl.iec.iec104.task;

import com.ydl.iec.iec104.config.Iec104Config;
import com.ydl.iec.iec104.core.CachedThreadPool;
import com.ydl.iec.iec104.server.Iec104SlaveFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.ConcurrentHashMap;



@Slf4j
@Component
public class IecServerInit {

    @PostConstruct
    public void StartIEC104Server(){
        log.info("启动104从站(服务端)---------------------开始");

        Runnable runnable = () -> {
            log.info("启动104从站(服务端)---------------------执行");
            try {
                Iec104Config iec104Config  = new Iec104Config();
                iec104Config.setFrameAmountMax((short) 1);
                iec104Config.setTerminnalAddress((short) 1);
                Iec104SlaveFactory.createTcpServerSlave(2404).setDataHandler(new SysDataHandler()).setConfig(iec104Config).run();

            } catch (Exception e) {
                log.error("104从站(服务端)  失败,{}",e.getMessage());
            }

        };

        CachedThreadPool.getCachedThreadPool().execute(runnable);

    }
}
